<?php if ( !defined('BASEPATH')) exit('No direct script access allowed');

class Mother_meter extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');

	}
	public function index(){
	  $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	  $this->load->view($this->session->userdata('formain'),array(
	  	));
	  $this->load->view('layouts/footer');
	 }


	public function insert_mom_meter(){
		$data = array(
			':p_mother_name'		=> 	$this->input->post('mm_name'),
			':p_serial_number'		=>	$this->input->post('mm_serial'),
			':p_model'				=>	$this->input->post('mm_model'),
			':p_description'		=>	$this->input->post('mm_desc'),
			':p_initial_reading'	=>	$this->input->post('mm_init'),
			':p_loc_latitude'		=>	$this->input->post('mm_lat'),
			':p_loc_longitude'		=>	$this->input->post('mm_lng'),
			':p_user_id'			=>	$this->session->userdata('user_id')
		);
		
		$this->mother_meter_model->insert_mom_meter($data);
	}

	public function update_mom_meter(){
		$data = array(
			':p_mmeter_id'			=> $this->input->post('e_hidden_id'),
			':p_mother_name'		=> $this->input->post('e_mm_name'),
			':p_serial_number'		=> $this->input->post('e_mm_serial'),
			':p_mother_model'		=> $this->input->post('e_mm_model'),
			':p_initial_reading'	=> $this->input->post('e_mm_init'),
			':p_description'		=> $this->input->post('e_mm_desc'),
			':p_latitude'			=> $this->input->post('e_mm_lat'),
			':p_longitude'			=> $this->input->post('e_mm_lng'),
			':p_user_id'			=> $this->session->userdata('user_id')
		);

		$this->mother_meter_model->update_mom_meter($data);
	}

	public function search_mom(){

		$query = $this->mother_meter_model->search_mom($this->input->post('mm_sname'));

		if(!empty($query)) {
			echo json_encode($query);
		}else{
			echo json_encode("none");
		}

	}	
     












    public function add_form(){
		$this->load->view($this->session->userdata('foradd'),array(
		));
	}
	public function edit_form($id){
		$result = $this->mother_meter_model->search_momID($id);
		$this->load->view($this->session->userdata('foredit'),array(
				'mm_data'	=>	$result
		));
	}
	public function view_form($id){
		$result = $this->mother_meter_model->search_momID($id);
		$this->load->view($this->session->userdata('forview'),array(
				'mm_data'	=>	$result
		));
	}



	

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */